$(function(){
    $("#carInfo_datagrid").datagrid({
        fit:true,
        url:"/carInfo/list",
        fitColumns:true,
        striped:true,
        pagination:true,
        singleSelect:true,
        toolbar:"#tb",
        rownumbers:true,
        columns:[[
            {field:'id',title:'编号', hidden:true},
            {field:'checkbox',checkbox:true,tilte:'选中',width:100},
            {field:'username',title:'车主姓名',align:'center',width:100},
            {field:'carnum',title:'车牌号码',align:'center',width:100},
            {field:'purchasedate',title:'购买日期',align:'center',width:100},
            {field:'carname',title:'车俩品牌',align:'center',width:100,formatter:function(value,row){
            return row.car.carname}},
            {field:'cartype',title:'车辆型号',align:'center',width:100,formatter:function(value,row){
            return row.car.cartype}},
            {field:'displacement',title:'排气量/L',align:'center',width:100,formatter:function(value,row){
            return row.car.displacement}},
            {field:'marketval',title:'市场估价/万',align:'center',width:100,formatter:function(value,row){
            return row.car.marketval}},
            {field:'carsizeId',title:'分类',align:'center',width:100,formatter:function(value,row){
                if(row.car.carsizeId==1){
                    return "小型"
                }else if(row.car.carsizeId==2){
                    return "中型"
                }else if(row.car.carsizeId==3){
                    return "大型"
                }
            }},
            {field:'sort',title:'车载大小',align:'center',width:100,formatter:function(value,row){
            if(row.car.sort){
                return "<p style='color: #00bbee'>载人</p>";
            }else{
                return "<p style='color: #e68900'>载物</p>";
            }
            }},
        ]]
    })
    $("#my_dialog").dialog({
        width:400,
        height:400,
        buttons:"#bb",
        closable:true,
        closed:true
    })
})
//编辑
function edits(){
    $("#editForm").form("clear");
    var row = $("#carInfo_datagrid").datagrid("getSelected");
    if(!row){
        $.messager.alert('温馨提示','请选择需要编辑的行');
    }else{
        $("#my_dialog").dialog("open");
        $("#my_dialog").dialog("setTitle","车辆信息编辑");
        if(row.car)
        {
            row["car.id"] = row.car.id;
        }
        $("#editForm").form("load",row);
    }
}
//保存数据
function save(){
    /*var id = $("#deptId").val();*/
    var url = "/carInfo/edit"
    /*if(id){
     url = "util_update.json";
     }*/
    $("#editForm").form("submit",{
        url:url,

        success:function(data){
            data =  $.parseJSON(data);
            if(!data.success){
                $.messager.alert('温馨提示',data.msg);
            }else{
                $("#my_dialog").dialog("close");
                $("#carInfo_datagrid").datagrid("reload");
            }
        }
    })
}
//刷新
function reload(){
    $("#carInfo_datagrid").datagrid("reload");
}
//取消
function cancel(){
    $("#my_dialog").dialog("close");
}
//高级查询
function query(){
    var keyword = $("#keyword").textbox("getValue");
    $("#carInfo_datagrid").datagrid("load",{
        keyword:keyword,
    })
    $('#carInfo_datagrid').datagrid('loadData', { total: 0, rows: [] });

}